import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.Layer;
import javax.microedition.lcdui.game.Sprite;

public final class Cls_4 extends Canvas
    implements CommandListener
{

    private int fld_39[];
    private int fld_40;
    private boolean fld_41;
    private int fld_42;
    private int fld_43;
    private boolean fld_44;
    public Cls_16 fld_45;
    public Sprite fld_46;
    public Graphics fld_47;
    public static boolean fld_48;
    public boolean fld_49;

    private int mth_34(int i)
    {
        if(Cls_8.fld_54 == 3)
        {
            if(i == -14)
                return -1;
            if(i == -13)
                return -2;
            if(i == -20 || i == -22)
                return 0;
            if(i == -11)
                return -5;
        }
        this;
        i;
        getKeyName();
        JVM INSTR dup ;
        String s;
        s;
        JVM INSTR ifnull 395;
           goto _L1 _L2
_L1:
        break MISSING_BLOCK_LABEL_57;
_L2:
        break MISSING_BLOCK_LABEL_395;
        if((s = s.toLowerCase()).equals("sk2(left)"))
            return -1;
        if(s.equals("sk1(right)"))
            return -2;
        if(i == 105)
            return -1;
        if(s.indexOf("soft") >= 0)
        {
            if(s.charAt(s.length() - 1) == '1' || s.startsWith("left"))
                return -1;
            if(s.charAt(s.length() - 1) == '2' || s.charAt(s.length() - 1) == '4' || s.startsWith("right"))
                return -2;
        }
        if(s.equals("clear") || s.equals("backspace") || s.equals("delete"))
            return -6;
        if(s.equals("back"))
            return -5;
        if(s.equals("select") || s.equals("ok") || s.equals("send") || s.equals("fire") || s.equals("navi-center") || s.equals("start") || s.equals("enter"))
            return 8;
        if(s.equals("up") || s.equals("navi-up") || s.equals("up arrow"))
            return 1;
        if(s.equals("down") || s.equals("navi-down") || s.equals("down arrow"))
            return 6;
        if(s.equals("left") || s.equals("navi-left") || s.equals("left arrow"))
            return 2;
        if(s.equals("right") || s.equals("navi-right") || s.equals("right arrow"))
            return 5;
        int j = 0;
        this;
        i;
        if(false) goto _L4; else goto _L3
_L4:
        j = 0;
        this;
        i;
_L3:
        getGameAction();
        j;
    }

    private synchronized void mth_35(int i)
    {
        fld_39 = Cls_16.mth_201(fld_39, fld_40 + 1);
        fld_39[fld_40++] = i;
    }

    private synchronized void mth_36(int i, int j)
    {
        fld_39 = Cls_16.mth_201(fld_39, fld_40 + 2);
        fld_39[fld_40++] = i;
        fld_39[fld_40++] = j;
    }

    public Cls_4(Cls_16 cls_16)
    {
        fld_39 = new int[32];
        fld_45 = cls_16;
    }

    private synchronized void mth_37(int i, int j, int k)
    {
        fld_39 = Cls_16.mth_201(fld_39, fld_40 + 3);
        fld_39[fld_40++] = i;
        fld_39[fld_40++] = j;
        fld_39[fld_40++] = k;
    }

    public final boolean mth_38()
    {
        if(false);
        return fld_49;
    }

    public final boolean mth_39()
    {
        return fld_40 > 0;
    }

    private static int mth_40(int i)
    {
        if(Cls_8.fld_65 != null && (i = Cls_8.fld_65.indexOf((char)i)) >= 0)
            return Cls_8.fld_66.charAt(i);
        else
            return 0;
    }

    private static int mth_41(int i)
    {
        int j;
        if((j = mth_40(i)) != 0)
            i = j;
        switch(i)
        {
        case 50: // '2'
            return 7;

        case 52: // '4'
            return 9;

        case 54: // '6'
            return 10;

        case 56: // '8'
            return 8;

        case 51: // '3'
        case 53: // '5'
        case 55: // '7'
        default:
            return 0;
        }
    }

    private int mth_42(int i)
    {
        if(mth_45())
            switch(i)
            {
            case 7: // '\007'
                return 9;

            case 9: // '\t'
                return 8;

            case 8: // '\b'
                return 10;

            case 10: // '\n'
                return 7;
            }
        return i;
    }

    private int mth_43(int i)
    {
        if(mth_38())
            switch(i)
            {
            case 1: // '\001'
                return 2;

            case 6: // '\006'
                return 5;

            case 2: // '\002'
                return 6;

            case 5: // '\005'
                return 1;
            }
        return i;
    }

    public final synchronized boolean mth_44()
    {
        byte byte0;
        if(fld_40 == 0)
            return false;
        byte0 = 1;
        fld_39[0];
        JVM INSTR tableswitch 0 7: default 621
    //                   0 64
    //                   1 75
    //                   2 86
    //                   3 281
    //                   4 358
    //                   5 426
    //                   6 494
    //                   7 563;
           goto _L1 _L2 _L3 _L4 _L5 _L6 _L7 _L8 _L9
_L1:
        break; /* Loop/switch isn't completed */
_L2:
        Cls_16.fld_301.mth_476(34);
        break; /* Loop/switch isn't completed */
_L3:
        Cls_16.fld_301.mth_476(35);
        break; /* Loop/switch isn't completed */
_L4:
        int i;
        byte0 = 2;
        i = fld_39[1];
        char ac[];
        if((ac = fld_45.mth_144(i)) == null || ac.length <= 0) goto _L11; else goto _L10
_L10:
        String s;
        s = String.valueOf(ac, 1, ac.length - 1);
        Cls_16.fld_279.mth_758(i);
        Cls_16.fld_279.mth_758(mth_40(i));
        Cls_16.fld_279.mth_758(i);
        Cls_16.fld_279.mth_758((int)Cls_16.mth_398());
        Cls_16.fld_279.mth_758(mth_42(mth_41(i)));
        Cls_16.fld_279.mth_745(Cls_16.fld_279.mth_140(s));
        Cls_16.fld_279;
        Cls_16.fld_279.mth_140(s.toUpperCase());
          goto _L12
_L11:
        Cls_16.fld_279.mth_758(mth_43(mth_34(i)));
        Cls_16.fld_279.mth_758(mth_40(i));
        Cls_16.fld_279.mth_758(i);
        Cls_16.fld_279.mth_758((int)Cls_16.mth_398());
        Cls_16.fld_279.mth_758(mth_42(mth_41(i)));
        Cls_16.fld_279.mth_745(0);
        Cls_16.fld_279;
        false;
_L12:
        mth_745();
        Cls_16.fld_301.mth_476(38);
        break; /* Loop/switch isn't completed */
_L5:
        byte0 = 2;
        i = fld_39[1];
        if((s = fld_45.mth_144(i)) == null || s.length <= 0) goto _L14; else goto _L13
_L13:
        Cls_16.fld_279;
        i;
          goto _L15
_L14:
        Cls_16.fld_279;
        mth_43(mth_34(i));
_L15:
        mth_758();
        Cls_16.fld_279.mth_758(i);
        Cls_16.fld_279.mth_758((int)Cls_16.mth_398());
        Cls_16.fld_301.mth_476(39);
        break; /* Loop/switch isn't completed */
_L6:
        byte0 = 3;
        int j = fld_39[1];
        int l = fld_39[2];
        Cls_16.fld_279.mth_758(mth_46(j, l));
        Cls_16.fld_279.mth_758(mth_47(j, l));
        Cls_16.fld_279.mth_758((int)Cls_16.mth_398());
        Cls_16.fld_279.mth_758(0);
        Cls_16.fld_301.mth_476(40);
        break; /* Loop/switch isn't completed */
_L7:
        byte0 = 3;
        int k = fld_39[1];
        int i1 = fld_39[2];
        Cls_16.fld_279.mth_758(mth_46(k, i1));
        Cls_16.fld_279.mth_758(mth_47(k, i1));
        Cls_16.fld_279.mth_758((int)Cls_16.mth_398());
        Cls_16.fld_279.mth_758(0);
        Cls_16.fld_301.mth_476(41);
        break; /* Loop/switch isn't completed */
_L8:
        fld_41 = false;
        Cls_16.fld_279.mth_758(mth_46(fld_42, fld_43));
        Cls_16.fld_279.mth_758(mth_47(fld_42, fld_43));
        Cls_16.fld_279.mth_758((int)Cls_16.mth_398());
        Cls_16.fld_279.mth_758(0);
        Cls_16.fld_301.mth_476(42);
        break; /* Loop/switch isn't completed */
_L9:
        byte0 = 2;
        Cls_16.fld_279.mth_745(Cls_16.mth_483(Cls_16.fld_244));
        Cls_16.fld_279.mth_758(fld_39[1]);
        Cls_16.fld_279.mth_758(1);
        Cls_16.fld_328 = Cls_16.mth_752(18);
        Cls_16.fld_331 = Cls_16.mth_755();
        Cls_16.mth_430(Cls_16.fld_244);
        Cls_16.fld_244 = 0;
        System.arraycopy(fld_39, byte0, fld_39, 0, fld_40 - byte0);
        fld_40 -= byte0;
        return true;
    }

    public final boolean mth_45()
    {
        if(false);
        return fld_49;
    }

    public final void paint(Graphics g)
    {
        if(mth_38())
        {
            int i = (g.getClipX() + g.getClipWidth()) - 1;
            int j = (g.getClipY() + g.getClipHeight()) - 1;
            g.drawLine(i, j, i, j);
            if(fld_46 == null || fld_46.getWidth() != getHeight() || fld_46.getHeight() != getWidth())
            {
                fld_46 = null;
                fld_47 = null;
                Image image = Image.createImage(getHeight(), getWidth());
                fld_47 = image.getGraphics();
                fld_46 = new Sprite(image);
                fld_46.setTransform(5);
                fld_46.setPosition(0, 0);
            }
            fld_47.setClip(g.getClipY(), getWidth() - g.getClipX() - g.getClipWidth(), g.getClipHeight(), g.getClipWidth());
            Browser.fld_1.mth_446(new Cls_16(fld_47));
            fld_46.paint(g);
            return;
        } else
        {
            if(fld_46 != null);
            fld_46 = null;
            fld_47 = null;
            Browser.fld_1.mth_446(new Cls_16(g));
            return;
        }
    }

    public final void keyPressed(int i)
    {
        Cls_16.mth_208();
        Cls_16.mth_252(i);
        if("STDERR".equals("NATIVE") && i == 57)
            return;
        if(!Cls_16.fld_190)
        {
            if(i == 53)
                Cls_16.fld_207 = true;
            return;
        }
        if(Cls_8.fld_73 && fld_44 && i == -5)
        {
            return;
        } else
        {
            int j;
            fld_44 = ((j = i - 10) | -j) >>> 31 ^ 1;
            mth_36(2, i);
            Cls_16.fld_301.mth_441();
            return;
        }
    }

    public final void keyReleased(int i)
    {
        Cls_16.mth_208();
        Cls_16.mth_252(i);
        Cls_16.mth_298(8);
        if(!Cls_16.fld_190)
            return;
        if(Cls_8.fld_73 && fld_44 && i == -5)
        {
            return;
        } else
        {
            fld_44 = false;
            mth_36(3, i);
            Cls_16.fld_301.mth_441();
            return;
        }
    }

    private int mth_46(int i, int j)
    {
        if(mth_38())
            return j;
        else
            return i;
    }

    private int mth_47(int i, int j)
    {
        if(mth_38())
            return getWidth() - i;
        else
            return j;
    }

    public final void pointerPressed(int i, int j)
    {
        Cls_16.mth_208();
        Cls_16.mth_252(i);
        Cls_16.mth_252(j);
        Cls_16.mth_298(1);
        if(!Cls_16.fld_190 || fld_48)
        {
            return;
        } else
        {
            fld_48 = true;
            mth_37(4, i, j);
            Cls_16.fld_301.mth_441();
            return;
        }
    }

    public final void pointerReleased(int i, int j)
    {
        Cls_16.mth_208();
        Cls_16.mth_252(i);
        Cls_16.mth_252(j);
        Cls_16.mth_298(1);
        if(!Cls_16.fld_190 || !fld_48)
        {
            return;
        } else
        {
            fld_48 = false;
            mth_37(5, i, j);
            Cls_16.fld_301.mth_441();
            return;
        }
    }

    public final void pointerDragged(int i, int j)
    {
        Cls_16.mth_208();
        Cls_16.mth_252(i);
        Cls_16.mth_252(j);
        Cls_16.mth_298(1);
        if(!Cls_16.fld_190 || !fld_48)
            return;
        Cls_4 cls_4 = this;
        JVM INSTR monitorenter ;
        fld_42 = i;
        fld_43 = j;
        if(!fld_41 && !Cls_16.fld_306)
        {
            fld_41 = true;
            mth_35(6);
        }
        Cls_16.fld_301.mth_441();
        return;
    }

    public final void showNotify()
    {
        if(!Cls_16.fld_190)
        {
            return;
        } else
        {
            mth_35(0);
            Cls_16.fld_301.mth_441();
            return;
        }
    }

    public final void hideNotify()
    {
        if(!Cls_16.fld_190)
        {
            return;
        } else
        {
            mth_35(1);
            Cls_16.fld_301.mth_441();
            return;
        }
    }

    public final void sizeChanged(int i, int j)
    {
        try
        {
            if(!Cls_16.fld_190)
            {
                repaint(0, 0, i, j);
                return;
            } else
            {
                Browser.fld_1.mth_335();
                return;
            }
        }
        finally
        {
            return;
        }
    }

    public final boolean mth_48()
    {
        return mth_45();
    }

    public final void commandAction(Command command, Displayable displayable)
    {
        int i;
        try
        {
            if(!Cls_16.fld_190)
            {
                return;
            } else
            {
                Browser.fld_5.setCurrent(this);
                mth_36(7, ((i = command.getCommandType() - 4) | -i) >>> 31 ^ 1);
                return;
            }
        }
        finally
        {
            return;
        }
    }

}